package com.hotelvip.common.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * @Description: 自定义分页相关数据的一个BO对象.
 * @author Lzh
 * @date 2020/11/30 09:55
 * @param <T>
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "page对象",description = "页面对象PageObject")
@AllArgsConstructor
public class PageObject<T> implements Serializable{
	private static final long serialVersionUID = -7452188623635031202L;
	/**记录总数*/
	@ApiModelProperty(value = "总记录数",name = "rowCount")
	private Long rowCount;
	/**当前页记录*/
	@ApiModelProperty(value = "当前页记录",name = "records")
	private List<T> records;
	/**总页数*/
	@ApiModelProperty(value = "总页数",name = "pageCount")
	private Long pageCount;
	/**页面大小*/
	@ApiModelProperty(value = "页面大小",name = "pageSize")
	private Long pageSize;
	/**当前页面值*/
	@ApiModelProperty(value = "当前页面值",name = "pageCurrent")
	private Long pageCurrent;
	
	public PageObject() {}

	public PageObject(Long rowCount, List<T> records, Long pageSize, Long pageCurrent) {
		super();
		this.rowCount = rowCount;
		this.records = records;
		this.pageSize = pageSize;
		this.pageCurrent = pageCurrent;
		//计算总页数
		//方法1:
//		this.pageCount=rowCount/pageSize;
//		if(rowCount%pageSize!=0) {
//			pageCount++;
//		}
		//方法2:
		this.pageCount=(rowCount-1)/pageSize+1;
	}
	public static PageObject setPageObject(Long rowCount, List records, Long pageSize, Long pageCurrent){
		return new PageObject(rowCount,records,pageSize,pageCurrent);
	}
    
	
}




